package com.onenine.app.view.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatDialog;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.onenine.app.R;
import com.onenine.app.activity.EditInfoActivity;
import com.onenine.app.utils.RoleResLoader;
import com.onenine.base.utils.Toasty;
import com.onenine.chat.rongcloud.RcUser;

/**
 * 完善资料弹窗
 */
public class InfoIncompleteDialog extends AppCompatDialog implements View.OnClickListener {

    private Context mContext;
    private ImageView mIvLogo;
    private Button mBtnWait, mBtnGoNow;

    public InfoIncompleteDialog(Context context) {
        super(context, R.style.DialogStyle);
        mContext = context;
        initView(context);
    }

    private void initView(Context context) {
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        View view = LayoutInflater.from(context)
                .inflate(R.layout.layout_info_incomplete_dialog, null);
        setContentView(view);
        mIvLogo = view.findViewById(R.id.iv_info_logo);
        mIvLogo.setImageResource(RoleResLoader
                .getRoleDrawableResourceId(RoleResLoader.DynamicResName.INFO_IMCOMPLETE_LOGO));
        mBtnWait = view.findViewById(R.id.btn_wait_moment);
        mBtnWait.setBackgroundResource(RoleResLoader
                .getRoleDrawableResourceId(RoleResLoader.DynamicResName.THEME_STROKE_WHITE_CORNER));
        mBtnWait.setTextColor(RoleResLoader.getRoleColorResourceId(RoleResLoader.DynamicResName.THEME_COLOR));
        mBtnGoNow = view.findViewById(R.id.btn_go_now);
        mBtnGoNow.setBackgroundResource(RoleResLoader
                .getRoleDrawableResourceId(RoleResLoader.DynamicResName.THEME_GRADIENT_CORNER_BG));
        mBtnWait.setOnClickListener(this);
        mBtnGoNow.setOnClickListener(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            dismiss();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_wait_moment) {
            dismiss();
        } else if (v.getId() == R.id.btn_go_now) {
            if (RcUser.getInstance().getInfoResponse() != null) {
                EditInfoActivity.launchActivity(mContext, true);
            } else {
                Toasty.showNormal(R.string.info_load_fail_un_edit);
            }
            dismiss();
        }
    }

}
